package com.xxxx.server.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xxxx.server.mapper.MenuMapper;
import com.xxxx.server.mapper.MenuRoleMapper;
import com.xxxx.server.pojo.Admin;
import com.xxxx.server.pojo.Menu;
import com.xxxx.server.service.IMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhoubin
 * @since 2020-08-17
 */
@Service
public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements IMenuService {

	@Resource
	private MenuMapper menuMapper;

	@Resource
	private MenuRoleMapper menuRoleMapper;

	/**
	 * 查询所有菜单
	 * @return
	 */
	@Override
	public List<Menu> getAllMenusByAdminId() {
		return menuMapper.getAllMenusByAdminId(((Admin)SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getId());
	}

	/**
	 * 查询菜单及角色
	 * @return
	 */
	@Override
	public List<Menu> getAllMenusWithRole() {
		return menuMapper.getAllMenusWithRole();
	}

	/**
	 * 查询所有菜单带分级
	 * @return
	 */
	@Override
	public List<Menu> queryAllMenus() {

		return menuMapper.queryAllMenus();
	}


	/**
	 *根据角色id查菜单id
	 */
	@Override
	public List<Integer> initSelectedMenus(Integer rId) {

		return menuRoleMapper.initSelectedMenus(rId);
	}
}
